package com.eling.elcms.travel.service.impl;

import com.eling.elcms.basedoc.model.OrgBuilding;
import com.eling.elcms.basedoc.service.IOrgBuildingManager;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.travel.dao.IDestnBuildingDao;
import com.eling.elcms.travel.model.DestnBuilding;
import com.eling.elcms.travel.service.IDestnBuildingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DestnBuildingManagerImpl extends GenericManagerImpl<DestnBuilding, Long> implements IDestnBuildingManager{
	
	IDestnBuildingDao destnBuildingDao;
	
	@Autowired
	public IOrgBuildingManager orgBuildingManager;
	
	@Autowired
	public void setDao(IDestnBuildingDao dao) {
        this.dao = dao;
        this.destnBuildingDao = dao;
    }


	@Override
	public List<OrgBuilding> queryBuilding(OrgBuilding cond) {
		List<OrgBuilding> returnList = orgBuildingManager.query(cond);
		
		List<DestnBuilding> destnBuildingList = destnBuildingDao.getAll();
		
		List<OrgBuilding> orgBuildingList = new ArrayList<OrgBuilding>();
		
		if(!returnList.isEmpty() && !destnBuildingList.isEmpty()){
			for(OrgBuilding orgB : returnList){
				for(DestnBuilding destnB : destnBuildingList){
					if(orgB.getPkOrgBuilding().equals(destnB.getOrgBuilding().getPkOrgBuilding())){
						orgBuildingList.add(orgB);
						break;
					}
				}
			}
		}
		if(!orgBuildingList.isEmpty()){
			returnList.removeAll(orgBuildingList);
		}
		
		return returnList;
	}
	
}
